<template>
    <el-upload class="upload-demo" 
    drag 
    :action="imageUploadApi"
    :headers="{token}"
     multiple
     :on-success="successHandler"
     :on-error="errorHandler"
     name="img"
     :data="data.data"
     >
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">
            Drop file here or <em>click to upload</em>
        </div>
        <template #tip>
            <div class="el-upload__tip">
                jpg/png files with a size less than 500kb
            </div>
        </template>
    </el-upload>
</template>
<script setup lang='ts'>
import { imageUploadApi } from '@/api/gallery'
import type { emitChangeFn, UploadFile , UploadFiles } from 'element-plus'
import { ElMessage } from 'element-plus'

const data = defineProps({
    data : Object
})

const emit = defineEmits(['success'])
// 上传成功回调
const successHandler = (response: any, uploadFile: UploadFile, uploadFiles: UploadFiles) => {
    emit('success',{response,uploadFile,uploadFiles})
    if(response.msg === 'ok'){
        ElMessage({
                type: 'success',
                message: '上传成功',
            })
    }
}
// 上传失败得回调
const errorHandler = () => {

}
const token = window.localStorage.getItem('token') || ''

</script>
<style lang='scss' scoped></style>